import { ref, reactive } from 'vue'

function defaultPage() {
  return {
    pageSizes: [10, 20, 30, 50, 100, 200, 500],
    pageNumber: 1,
    pageSize: 10,
    data: [],
    total: 0
  }
}

// 表格混合
export default function () {
  const selectNum = ref(0)

  const page = reactive({
    pageSizes: [10, 20, 30, 50, 100, 200, 500],
    pageNumber: 1,
    pageSize: 10,
    data: [],
    total: 0
  })

  function changeSelect(selection: Array<any>) {
    selectNum.value = selection.length
  }

  function initIndex(index: number) {
    return page.pageSize * (page.pageNumber - 1) + (index + 1)
  }

  function resetPage() {
    Object.assign(page, defaultPage())
  }

  return {
    selectNum,
    page,
    changeSelect,
    initIndex,
    resetPage
  }
}
